package com.lsc.jdbc.demo.jdbc;

import java.sql.*;

/**

 */
public class JdbcTest {

    public static void main(String[] args) {


        /* 激活静态代码 加载驱动对象 */
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("驱动加载异常！");
            e.printStackTrace();
        }

        String url = "jdbc:mysql://127.0.0.1:3306/hanamaki?serverTimezone=UTC";
        String username = "root";
        String password = "root";

        try {
            Connection connection = DriverManager.getConnection(url, username, password);

            /* 常见数据库查询对象 */
            Statement statement = connection.createStatement();
            String sql = "SELECT stu_name from stu_info";
            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                System.out.println(resultSet.getObject("stu_name"));
            }

            resultSet.close();
            statement.close();
            connection.close();

        } catch (SQLException throwables) {
            System.out.println("数据库连接异常！");
            throwables.printStackTrace();
        }


    }

}
